// utils/request.js
// 数据请求
// axios.get() axios.post() axios({})
// https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
// 加载数据显示loading动画
// https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.showLoading.html
const baseUrl = "http://121.89.205.189:3000/api"

const request = (config) => {
  let { url, method = 'GET', header = {}, data = {} } = config
  // method = method || 'GET'
  wx.showLoading({
    title: '加载中',
  })
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method: method,
      header: header,
      data: data,
      success: res => {
        resolve(res)
      },
      fail: () => {
        reject()
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  })
}

export default request